package mulot;

import level.Plateau;
import level.iMulot;
import level.iTexture;
import level.mulotPerso;
import outils.Direction;
import affichage.textureParachutiste;

public class Parachutiste extends Mulot implements iMulot{

	private boolean etatMetier;

	public Parachutiste(int x, int y, mulotPerso deleg) {
		super(x, y, deleg);
		etatMetier=false;
	}
	
	public Parachutiste(iMulot m){
		super(m);
	}
	
	public void deplacer(Plateau p){
		applicationMetier(p);
		super.deplacer(p);
	}
	
	public void afficher(iTexture[][] tab){
		int x = getX();
		int y = getY();
		Direction d = getD();
		
		tab[x][y] = new textureParachutiste(isMort(),d);
	} 
	
	private void applicationMetier(Plateau p){
		int yMax = p.getPlateau()[0].length;
		mulotPerso deleg = getDeleg();
		int x = getX();
		int y = getY();
				
		if(y<yMax-1){
			if(!etatMetier){
				if(p.getPlateau()[x][y+1].traversable()){
					etatMetier=true;
					setChute(0);
				}
			}
			else{
				if(!p.getPlateau()[x][y+1].traversable()){
					setChute(0);
					deleg.changerVersMulot(p);
				}
				else{
					setChute(0);
				}				
			}
		}
		else{
			deleg.changerVersMulot(p);
		}
	}
	
}
